import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;              
import java.awt.event.*;       
import java.net.URL;
import java.io.*;
import java.lang.Object;
import java.util.Properties;
 
 
        //formatka wyboru formatu transmisji
class LanOrWanFrame extends JFrame{
		Properties wlasciwosci = PropertyLoader.load("conf/System.properties"); 		
                String NString = wlasciwosci.getProperty("NETWORK");
                
                public LanOrWanFrame(){
                  
                setTitle("Okno wyboru rodzaju sieci ");
                setResizable(false);
                setSize(350,100);
                JLabel text3 = new JLabel("Wybierz siec dla transmisji :");
                text3.setAlignmentX(CENTER_ALIGNMENT);
                getContentPane().add(text3,BorderLayout.CENTER);
                
                final JCheckBox N1Box = new JCheckBox("Siec LAN");
                final JCheckBox N2Box = new JCheckBox("Internet");
            
                N1Box.addActionListener(new ActionListener(){
                		
         public void actionPerformed(ActionEvent e){
                        N1Box.updateUI();
                        if (N1Box.isSelected()){
                        	N2Box.setSelected(false);}
                        	 else N2Box.setSelected(true);
                       try{
                        wlasciwosci.setProperty("NETWORK","LAN");
                        FileOutputStream os = new FileOutputStream("conf/System.properties");
                        wlasciwosci.store(os,"Zmiana ustawien");
                        }catch(FileNotFoundException fnfe){}
                          catch(IOException ioe){}
                        }
                        });
                
                
                
                N2Box.addActionListener(new ActionListener(){
                
         public void actionPerformed(ActionEvent e){
                      String ipWan = JOptionPane.showInputDialog("podaj adres IP zewnetrzny :");
                      
                      N2Box.updateUI(); //Aktualizacja stanu
                       try{
                        wlasciwosci.setProperty("NETWORK",ipWan);
                        Komunikator.caly_adres=ipWan;
                        FileOutputStream os = new FileOutputStream("conf/System.properties");
                        wlasciwosci.store(os,"Zmiana ustawien");
                        }catch(FileNotFoundException fnfe){}
                          catch(IOException ioe){}
                      
                      //Wylaczania opcji wyboru jezeli zaznaczony
                        if (N2Box.isSelected()==true){
                    	N1Box.setSelected(false);	
                    	}
                    	else N1Box.setSelected(true);
                        }
                        });
                
                
                N2Box.isValid();      
                JPanel NPanel = new JPanel();
                
               
                NPanel.add(N1Box);
                NPanel.add(N2Box);
                getContentPane().add(NPanel,BorderLayout.SOUTH);
                
                    if (NString.equals("LAN")){
                        N1Box.setSelected(true);
                        }else{N2Box.setSelected(true);
                        }
                }
	}
